using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Specialized;

namespace CodePlex.Resourceful.Examples
{
    public static class DeliciousExample
    {

        public static void Run()
        {





            // del.icio.us account info
            string info = Environment.GetEnvironmentVariable("DEL_ICIO_US");

            string username = info.Split(':')[0];
            string password = info.Split(':')[1];


            // create client (service requires https) - http trace to standard out
            Client client = new Client(new Uri("https://api.del.icio.us/v1/"));
            client.Tracer.AddListener(Console.Out);
            client.Throttle = TimeSpan.FromSeconds(1.5);
           

            // authentication
            client.SetBasicAuth("", username, password);  

            
            //https://api.del.icio.us/v1/posts/get?
            //Returns posts matching the arguments. If no date or url is given, most recent date will be used.
            client.GetRepresentation("posts/get");

            //https://api.del.icio.us/v1/posts/recent?
            //Returns a list of the most recent posts, filtered by argument. Maximum 100.
            client.GetRepresentation("posts/recent");


            //https://api.del.icio.us/v1/posts/add?
            //Add a post to del.icio.us
            //&url (required) - the url of the item.
            //&description (required) - the description of the item.
            //&extended (optional) - notes for the item.
            //&tags (optional) - tags for the item (space delimited).
            //&dt (optional) - datestamp of the item (format "CCYY-MM-DDThh:mm:ssZ").
            //  Requires a LITERAL "T" and "Z" like in ISO8601 at http://www.cl.cam.ac.uk/~mgk25/iso-time.html for example: "1984-09-01T14:21:31Z"
            //&replace=no (optional) - don't replace post if given url has already been posted.
            //&shared=no (optional) - make the item private


            NameValuePairs parameters = new NameValuePairs();
            parameters["url"] = "http://www.ask.com/";
            parameters["description"] = "ask.com search engine 2";
            parameters["shared"] = "no";

            client.GetRepresentation("posts/add", parameters);


            // check
            client.GetRepresentation("posts/recent");




            //https://api.del.icio.us/v1/posts/delete?
            //Delete a post from del.icio.us
            //&url (required) - the url of the item.
            parameters = new NameValuePairs();
            parameters["url"] = "http://www.ask.com/";
            client.GetRepresentation("posts/delete",parameters);


            // check
            client.GetRepresentation("posts/recent");


            Utils.Prompt();








        }
























    }
}
